<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="numId" />
		<input type="button" value="猜" onclick="guess()" />
		=
		<span id="resultId"></span>
		
		<script type="text/javascript">
			var random = parseInt(Math.random() * 100 + 1);
			console.log('random: ' + random);
			function guess() {
				var num = document.getElementById('numId').value;
				var resultSpan = document.getElementById('resultId');
				// NaN:Not a Number   isNaN()
				if(isNaN(num) || num == '') {
					resultSpan.innerHTML = '<span style="color: red;">您输入的不是一个数字</span>';
					return;
				}
				
				if (num > random) {
					resultSpan.innerText = '猜大了';
				} else if(num < random) {
					resultSpan.innerText = '猜小了';
				} else {
					resultSpan.innerText = '猜对了';
				}
			}
		</script>
	</body>
</html>
